from typing import Any, Union

from pymysql import *
from pymysql.connections import Connection
from pymysql.cursors import Cursor

mysql_host = 'localhost'
mysql_port = 3306
mysql_user = 'root'
mysql_password = 'haosql'
mysql_database = 'jing_dong'
mysql_charset = 'utf8'
sql1 = "select * from t_users;"
conn: Connection = connect(host=mysql_host, port=mysql_port, user=mysql_user, password=mysql_password,
                           database=mysql_database,
                           charset=mysql_charset)
cursor: Union[Cursor, Any] = conn.cursor()
res = cursor.execute(sql1)
# print(cursor.fetchall())  # ((1, '张三'), (2, '李四'), (3, '王五'), (4, '赵六'))
# print(cursor.fetchmany(2)) # ((1, '张三'), (2, '李四'))
print(cursor.fetchone())
cursor.close()
conn.close()